def funt(arr,n):
c=0
for i in range(n):
if arr[0][i]==arr[1][i] or (arr[0][i] == 'G' and arr[1][i] == 'B') or (arr[0][i] == 'B' and arr[1][i] == 'G'):
c+=1
return c==n
for _ in range(int(input())):
n=int(input())
l=[]
for i in range(2):
l.append(list(input()))
if funt(l,n):
print("YES")
else:
print("NO")
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define LM10 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
/*
bool f = false;
int cnt = 0 ;
int partition (int arr[] , int l , int h)
{
int p = arr[l] ;
int i= l ;
int j=h ;
while(i<j)
{
do {
{
i++ ;
}
}while (arr[i]<=p) ;
do {
j-- ;
}while(arr[j]>p) ;
if(i<j)
{
swap(arr[i],arr[j]) ;
f=true ;
}
}
if (f)
cnt++ ;
swap(arr[l],arr[j]) ;
return j ;
}
void quicksort (int arr[], int left , int right)
{
if (left<right)
{
int piv = partition(arr , left ,right) ;
quicksort(arr,left,piv) ;
quicksort(arr,piv+1,right) ;
}
}
*/
/*
int n , m , cnt = 0 ;
ll s = 0 ,sum = 0 ;
void solve() {
cin>>n>>m ;
ll bytesComp [10004]={};
while(n--)
{
int a , b ;
cin>>a>>b ;
s+=a;
bytesComp[cnt] = a-b ;
cnt++ ;
}
bool f = false ;
sort(bytesComp , bytesComp+cnt) ;
for (int i = 0; i < cnt; ++i) {
cout<<bytesComp[i]<<' ';
}
cout<<"\n" ;
for (int i = 0; i < cnt; ++i) {
sum+= bytesComp[i] ;
if (sum==s-m){
cout<<i ;
f=true ;
break;
}
}
if (f==false)
cout<<-1 ;
}
*/
int n ;
bool f =true ;
void solve () {
cin >> n;
char arr[2][n];
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < n; ++j) {
cin >> arr[i][j];
if (arr[i][j]=='G')
arr[i][j]='B' ;
}
}
for (int j = 0; j < n; ++j)
{
if (arr[0][j]!=arr[1][j])
{
f=false ;
break;
}
}
if (f)
cout<<"YES\n" ;
else
cout<<"NO\n" ;
}
int main(void) {
LM10
int tt ;
cin>>tt ;
while(tt--)
{
solve() ;
f=true ;
}
}
122A - Lucky Division | 1611C - Polycarp Recovers the Permutation |
432A - Choosing Teams | 758A - Holiday Of Equality |
1650C - Weight of the System of Nested Segments | 1097A - Gennady and a Card Game |
248A - Cupboards | 1641A - Great Sequence |
1537A - Arithmetic Array | 1370A - Maximum GCD |
149A - Business trip | 34A - Reconnaissance 2 |
59A - Word | 462B - Appleman and Card Game |
1560C - Infinity Table | 1605C - Dominant Character |
1399A - Remove Smallest | 208A - Dubstep |
1581A - CQXYM Count Permutations | 337A - Puzzles |
495A - Digital Counter | 796A - Buying A House |
67A - Partial Teacher | 116A - Tram |
1472B - Fair Division | 1281C - Cut and Paste |
141A - Amusing Joke | 112A - Petya and Strings |
677A - Vanya and Fence | 1621A - Stable Arrangement of Rooks |